<template>
  <div 
    class="apple-loader" 
    :class="[
      `apple-loader--size-${size}`,
      { 'apple-loader--overlay': overlay }
    ]"
  >
    <div class="apple-loader__container">
      <div v-if="type === 'spinner'" class="apple-loader__spinner">
        <div class="apple-loader__spinner-circle"></div>
      </div>
      
      <div v-else-if="type === 'dots'" class="apple-loader__dots">
        <span class="apple-loader__dot"></span>
        <span class="apple-loader__dot"></span>
        <span class="apple-loader__dot"></span>
      </div>
      
      <div v-else-if="type === 'pulse'" class="apple-loader__pulse">
        <span class="apple-loader__pulse-circle"></span>
      </div>
      
      <div v-else class="apple-loader__progress">
        <div class="apple-loader__progress-bar" :style="{ width: `${progress}%` }"></div>
      </div>
      
      <div v-if="message" class="apple-loader__message">{{ message }}</div>
    </div>
  </div>
</template>

<script setup>
const props = defineProps({
  // 加载中的类型：spinner（旋转加载）、dots（点动画）、pulse（脉冲）、progress（进度条）
  type: {
    type: String,
    default: 'spinner',
    validator: (value) => ['spinner', 'dots', 'pulse', 'progress'].includes(value)
  },
  // 加载动画的大小：sm、md、lg
  size: {
    type: String,
    default: 'md',
    validator: (value) => ['sm', 'md', 'lg'].includes(value)
  },
  // 进度条类型时的进度值（0-100）
  progress: {
    type: Number,
    default: 0,
    validator: (value) => value >= 0 && value <= 100
  },
  // 是否作为覆盖层显示
  overlay: {
    type: Boolean,
    default: false
  },
  // 加载提示信息
  message: {
    type: String,
    default: ''
  }
});
</script>

<style scoped>
.apple-loader {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

/* 覆盖层样式 */
.apple-loader--overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(5px);
  z-index: var(--z-index-modal, 1000);
}

.apple-loader__container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* 加载器大小 */
.apple-loader--size-sm .apple-loader__spinner,
.apple-loader--size-sm .apple-loader__pulse {
  width: 24px;
  height: 24px;
}

.apple-loader--size-md .apple-loader__spinner,
.apple-loader--size-md .apple-loader__pulse {
  width: 40px;
  height: 40px;
}

.apple-loader--size-lg .apple-loader__spinner,
.apple-loader--size-lg .apple-loader__pulse {
  width: 60px;
  height: 60px;
}

/* 加载提示文字 */
.apple-loader__message {
  margin-top: 12px;
  font-size: 14px;
  color: var(--apple-text-secondary-light, #6e6e73);
  text-align: center;
}

/* 旋转加载动画 */
.apple-loader__spinner {
  position: relative;
  display: inline-block;
}

.apple-loader__spinner-circle {
  width: 100%;
  height: 100%;
  border: 3px solid rgba(0, 122, 255, 0.15);
  border-top-color: var(--apple-primary, #007aff);
  border-radius: 50%;
  animation: apple-loader-spin 0.8s linear infinite;
}

@keyframes apple-loader-spin {
  to { transform: rotate(360deg); }
}

/* 点动画 */
.apple-loader__dots {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.apple-loader--size-sm .apple-loader__dot {
  width: 6px;
  height: 6px;
}

.apple-loader--size-md .apple-loader__dot {
  width: 8px;
  height: 8px;
}

.apple-loader--size-lg .apple-loader__dot {
  width: 10px;
  height: 10px;
}

.apple-loader__dot {
  display: inline-block;
  border-radius: 50%;
  background-color: var(--apple-primary, #007aff);
  animation: apple-loader-pulse 1.4s infinite ease-in-out both;
}

.apple-loader__dot:nth-child(1) {
  animation-delay: -0.32s;
}

.apple-loader__dot:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes apple-loader-pulse {
  0%, 80%, 100% { 
    transform: scale(0);
    opacity: 0.3;
  }
  40% { 
    transform: scale(1);
    opacity: 1;
  }
}

/* 脉冲动画 */
.apple-loader__pulse {
  position: relative;
  display: inline-block;
}

.apple-loader__pulse-circle {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--apple-primary, #007aff);
  border-radius: 50%;
  opacity: 0.6;
  animation: apple-loader-ripple 1.5s infinite ease-in-out;
}

.apple-loader__pulse-circle::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--apple-primary, #007aff);
  border-radius: 50%;
  animation: apple-loader-ripple 1.5s infinite ease-in-out;
  animation-delay: 0.75s;
}

@keyframes apple-loader-ripple {
  0% {
    transform: scale(0);
    opacity: 1;
  }
  100% {
    transform: scale(2);
    opacity: 0;
  }
}

/* 进度条动画 */
.apple-loader__progress {
  width: 100%;
  height: 6px;
  background-color: rgba(0, 122, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.apple-loader--size-sm .apple-loader__progress {
  width: 100px;
}

.apple-loader--size-md .apple-loader__progress {
  width: 180px;
}

.apple-loader--size-lg .apple-loader__progress {
  width: 240px;
}

.apple-loader__progress-bar {
  height: 100%;
  background: linear-gradient(to right, #007aff, #5ac8fa);
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* 深色模式适配 */
@media (prefers-color-scheme: dark) {
  .apple-loader--overlay {
    background-color: rgba(28, 28, 30, 0.8);
  }
  
  .apple-loader__message {
    color: var(--apple-text-secondary-dark, #a1a1a6);
  }
  
  .apple-loader__spinner-circle {
    border-color: rgba(10, 132, 255, 0.15);
    border-top-color: var(--apple-primary-dark, #0a84ff);
  }
  
  .apple-loader__dot {
    background-color: var(--apple-primary-dark, #0a84ff);
  }
  
  .apple-loader__pulse-circle {
    background-color: var(--apple-primary-dark, #0a84ff);
  }
  
  .apple-loader__pulse-circle::after {
    background-color: var(--apple-primary-dark, #0a84ff);
  }
  
  .apple-loader__progress {
    background-color: rgba(10, 132, 255, 0.1);
  }
  
  .apple-loader__progress-bar {
    background: linear-gradient(to right, #0a84ff, #64d2ff);
  }
}
</style> 